<?php
class Customer_Form_Route extends TBB_Form
{	
	public function init()
	{	
		// uncomment out this line to use 
		//$this->addAttribs(array('autocomplete' => 'off'));
		
		$this->addAttribs(array(
			'class' => 'span-6',
		));

		// datepicker
		$date = $this->_createDateElement();
		
		// submit button
		$find = $this->_createSubmitElement();
		
		$this->addElements(array($date, $find));
		$this->addDisplayGroup(array('date', 'find'), 'routeGroup');
		        
		$this->setDecorators($this->_formDecorators);		
		$this->setDisplayGroupDecorators($this->_displayGroupDecorators);
		
		// override fieldset class
		$this->getDisplayGroup('routeGroup')->setAttrib('class', 'fieldsetFormNav');
	}
	
	public function addFromToCityElement($cities = array())
	{
		// create from element
		$from = $this->createElement('select', 'from')
					 ->setLabel('Từ: ')
			 		 ->setMultiOptions($cities)
			 		 ->setValue('Hồ Chí Minh')		 		 		
			 		 ->setOrder(0);
		$from->setAttribs(array(
			'class' => 'span-4'
		));	
		$from->getDecorator('Label')->setOption('class', 'span-2 labelDecoratorNav');
				
		// create to element		
		$to = $this->createElement('select', 'to')
				   ->setLabel('Đến: ')
			 	   ->setMultiOptions($cities)
			 	   ->setValue('Hà Nội')
			 	   ->setOrder(1);
		$to->setAttribs(array(
			'class' => 'span-4'
		));	
		$to->getDecorator('Label')->setOption('class', 'span-2 labelDecoratorNav');
		
		// add from and to elements to display group
		$this->getDisplayGroup('routeGroup')->addElements(array($from, $to));		
	}
	
	private function _createSubmitElement()
	{
		$find = $this->createElement('submit', 'find');
		$find->setLabel('Tìm chuyến');
		$find->setDecorators($this->_submitDecorators);
		$find->getDecorator('HtmlTag')->setOption('id', 'findTripButton');		
		$find->setAttribs(array(
			'class' => 'span-3 submitDecorator'
		));
		return $find;
	}
	
	private function _createDateElement()
	{
		$date = new ZendX_JQuery_Form_Element_DatePicker(
			'date',
			array(
				'JQueryParams' => array(
										'dateFormat' => 'dd-mm-yy',
										'defaultDate' => time())
			)
		);
		$date->setAttrib('class', 'span-4');
		$date->setLabel('Ngày đi: ');
		$date->setAttribs(array(
			'class' => 'span-4',
		));
		$date->getDecorator('Label')->setOption('class', 'span-2 labelDecoratorNav');		
		return $date;
	}
}